using System;
using System.Web;
using System.Collections.Generic;
using System.Text;

namespace TaiLieu
{
    public class QueryHelper
    {
        public static string Get_Domain(HttpRequest request)
        {
            return request.Url.Host.ToString();
        }
        /// <summary>
        /// bỏ phần mở rộng
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static string Get_Domain_1(HttpRequest request)
        {
            //if (Get_Domain(request).Split('.')[0] == Domain.localhost)
            //    return Domain.ecoliving;
            return Get_Domain(request).Split('.')[0];
        }
        /// <summary>
        /// bỏ phần mở rộng rồi mã hóa 
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static string Get_Domain_1_maHoa(HttpRequest request)
        {
            string tam = "";
            //if (Get_Domain(request).Split('.')[0] == Domain.localhost)
            //    tam = "suachuamaytinh";s
            //else
                tam=Get_Domain(request).Split('.')[0];
            return maHoa.GetMD5HashData(tam);
        }
        public static string Get_Query(HttpRequest request)
        {
            return request.Url.Query.Replace("?", "").Replace("%2f","/");
        }
        public static string Get_Value(HttpRequest request, int position)
        {
            string query = Get_Query(request);// request.Url.Query;
            try
            {
                return query.Split('/')[position];
            }
            catch { return ""; }
        }
        //
        public static string Get_Value_TheEndOfQueryString(HttpRequest request)
        {
            string query = Get_Query(request);//request.Url.Query;
            int lengh = query.Split('/').Length - 1;
            return Get_Value(request, lengh);
        }
        // get query string 
        public static string GetQueryString(HttpRequest request, string query)
        {
            try
            {
                return request.QueryString[query].ToString();
            }
            catch
            {
                return "";
            }
        }

    }
}
